import { ajax, tools } from './ajax.js';

//#region 邮箱找回密码的部分
let txt_username = document.getElementById('txt_username');
let txt_code = document.getElementById('txt_code');
let btnSend = document.getElementById('btnSend');
let txt_password = document.getElementById('txt_password');
let btnOk = document.getElementById('btnOk');

btnSend.addEventListener('click', () => {
  ajax.post(
    '/tool/sendUserEmailCode',
    {
      username: txt_username.value,
    },
    (data) => {
      showToast(data.message);
    }
  );
});

btnOk.addEventListener('click', () => {
  let info = {
    username: txt_username.value,
    code: txt_code.value,
    password: tools.md5(txt_password.value),
  };

  ajax.post('/user/auth/findPwdByEmail', info, (data) => {
    showToast(data.message);
  });
});

//#endregion

//#region 信息弹出层的部分
let divToast = document.getElementById('divToast');
// querySelector是通过css选择器获取页面元素（只会返回一个）
let toastBody = document.querySelector('#divToast .toast-body');
// 创建toast对象
const toast = new bootstrap.Toast(divToast);

// 显示toast对话框
function showToast(message) {
  // 修改内容
  toastBody.innerHTML = message;
  // 显示
  toast.show();
}
//#endregion
